<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
  <title>Document</title>
  <style>

  </style>
</head>

<body>
  <h1>Index</h1>
  <!-- <form action="/login" method="post"> -->
    <p>Name: <input type="text" name="name" id="name"></p>

    <p>Password: <input type="password" name="password" id="password"></p>
    <p><input type="button" value="登陆" id="btn"/></p>
    <p><input type="button" value="注册" id="re"/></p>
  <!-- </form> -->
  <script>
  $('#btn').on('click', function() {
    $.ajax({
      url: '/login',
      type: 'post',
      data: {
        name: $('#name').val(),
        password: $('#password').val()
      },
      success: function(res) {
        alert('login' + res.message)
        window.location.href = '/blogList'
        // console.log(res)
      },
      error: function () {
        alert('login wrong!!!')
      }
    })
  })


  $('#re').on('click', function() {
    $.ajax({
      url: '/register',
      type: 'post',
      data: {
        name: $('#name').val(),
        password: $('#password').val()
      },
      success: function(res) {
        // console.log(res)
        alert('register' + res.message)
      },
      error: function () {
        alert('register wrong!!!')
      }
    })
  })
  </script>
</body>
</html>